﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace TOTTO.FINGERPRINT.SERVICIOS.Utilidades.Complementos
{
    public class SqlHelper
    {
        public static string ObtenerConecctionString()
        {
            return System.Configuration.ConfigurationManager.ConnectionStrings[Constantes.CONNECTIONSTRING].ConnectionString;
        }
        public static SqlDataReader EjecutarConsulta(string Consulta, SqlConnection _sqlConnect)
        {
            SqlCommand _sqlcommand = new SqlCommand();
            SqlDataReader _reader = null;

            try
            {
                _sqlConnect.ConnectionString = ObtenerConecctionString();
                _sqlcommand.CommandText = Consulta;
                _sqlcommand.Connection = _sqlConnect;
                _sqlConnect.Open();
                SqlDataAdapter _adapter = new SqlDataAdapter(_sqlcommand);
                _reader = _sqlcommand.ExecuteReader();
            }

            catch (SqlException SqlEx)
            {
                return null;
            }
            catch (Exception Ex)
            {
                return null;
            }

            return _reader;
        }
        public static bool EjecutarScript(string script)
        {
            SqlConnection _sqlConnect = new SqlConnection();
            SqlCommand _sqlcommand = new SqlCommand();

            try
            {
                _sqlConnect.ConnectionString = ObtenerConecctionString();
                _sqlcommand.CommandText = script;
                _sqlcommand.Connection = _sqlConnect;
                _sqlConnect.Open();
                _sqlcommand.Dispose();
                _sqlcommand.ExecuteNonQuery();
                _sqlConnect.Close();
            }
            catch (Exception Ex)
            {
                return false;
            }

            return true;
        }

    }
}